<?php
/**
 * User: aka
 * Time: 1:38
 */

namespace app\tenno\controller;

use app\tenno\model\UsersComment;
use app\tenno\model\UsersFile;
use think\facade\Session;
use think\Request;

class Users
{
    private $userId;

    public function __construct()
    {
        $this->userId = Session::get('user_info.id');
    }

    public function __destruct()
    {
        unset(
            $this->userId
        );
    }

    public function signIn()
    {
        return view();
    }

    public function signUp()
    {
        return view();
    }

    public function editGameId()
    {
        return view();
    }

    public function editPassword()
    {
        return view();
    }

    public function editUserFile()
    {
        $userFile = UsersFile::file($this->userId)->find();
        return view('edit_user_file', ['user_file' => $userFile]);
    }

    public function userFile(Request $request)
    {
        $userId = base64_decode($request->param('user_id'));
        $userInfo = \app\tenno\model\Users::userInfo($userId)->find();
        $userFile = UsersFile::file($userId)->find();
        $modList = \app\tenno\model\Mod::UserFileData(0)->uid($userId)->select();
        $weaponList = \app\tenno\model\Prime::UserFileData(0)->type(1)->uid($userId)->select();
        $warFrameList = \app\tenno\model\Prime::UserFileData(0)->type(2)->uid($userId)->select();
        $rivenList = \app\tenno\model\Riven::UserFileData(0)->uid($userId)->select();
        $otherList = \app\tenno\model\Other::UserFileData(0)->uid($userId)->select();
        return view('user_file',
            [
                'user_info' => $userInfo,
                'user_file' => $userFile,
                'user_id' => $userId,
                'mod_list' => $modList,
                'weapon_list' => $weaponList,
                'war_frame_list' => $warFrameList,
                'riven_list' => $rivenList,
                'other_list' => $otherList,
            ]);
    }

    public function comment()
    {
        $commentList = UsersComment::uid($this->userId)->deleteState(0)->paginate(10)
            ->each(
                function($item)
                {
                    $item->comment_uid = \app\tenno\model\Users::userInfo($item->comment_uid)
                        ->find();
                }
            );
        return view('comment', ['comment_list' => $commentList]);
    }

    public function forgetPassword()
    {
        return view('forget_password');
    }
}